package SecondeStage.IO.In_OutputStream;

import java.io.*;

public class BufferedCopy {
    public static void main(String[] args) {
        // BufferedInputStream和BufferedOutputStream是按照字节操作的,可以完成二进制文件拷贝（文本，图片，视频）
        String srcFilePath ="D:\\Java\\JavaProject\\hello.txt";
        String destFilePath = "D:\\Java\\JavaProject\\note.txt";
        // 创建BufferedInputStream和BufferedOutputStream对象
        BufferedInputStream bis=null;
        BufferedOutputStream bos=null;
        try {
            bis = new BufferedInputStream(new FileInputStream(srcFilePath));
            bos = new BufferedOutputStream(new FileOutputStream(destFilePath));
            byte[] buf =new byte[1024];
            int readLen =0;
            while ((readLen=bis.read(buf))!= -1){
                bos.write(buf,0, readLen);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            // 关闭外层处理流
            try {
                if(bis!=null){
                    bis.close();
                }
                if(bos!=null){
                    bos.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
